<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace common\behavior;

use common\model\ProjectRelationTemplateTodoModel;
use Webman\Stomp\Client;

/**
 * 行为扩展：标准任务模板配置更新行为扩展
 */
class TemplateTodoUpdateBehavior
{

    /**
     * @param $data
     * @return void
     * @throws \Exception
     */
    public function run(&$data)
    {
        if (empty($data['template_todo_id'])) {
            return;
        }
        // 如果发起人有修改,则发起人模板配置清空
        if (!empty($data['start_man_is_update'])) {
            model(ProjectRelationTemplateTodoModel::class)->where([
                'template_todo_id' => $data['template_todo_id'],
            ])->save(['start_man' => null, 'is_open' => 'no']);
        }
        // 如果执行人有修改,则执行人模板配置清空
        if (!empty($data['participant_man_is_update'])) {
            model(ProjectRelationTemplateTodoModel::class)->where([
                'template_todo_id' => $data['template_todo_id']
            ])->save(['participant_man' => null, 'is_open' => 'no']);
        }
        // 如果准备事项有修改,则准备事项模板配置清空
        if (!empty($data['job_option_is_update'])) {
            model(ProjectRelationTemplateTodoModel::class)->where([
                'template_todo_id' => $data['template_todo_id']
            ])->save(['job_option' => null, 'is_open' => 'no']);
        }
        // 如果后续事项有修改,则后续事项模板配置清空
        if (!empty($data['after_option_is_update'])) {
            model(ProjectRelationTemplateTodoModel::class)->where([
                'template_todo_id' => $data['template_todo_id']
            ])->save(['after_option' => null, 'is_open' => 'no']);
        }
    }

}
